package com.xugongzhang.autowire.config;

import com.xugongzhang.autowire.bean.Boss;
import com.xugongzhang.autowire.bean.MyCar;
import com.xugongzhang.autowire.condition.BossCondition;
import com.xugongzhang.autowire.dao.BookDao;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author X
 * @date 2022/12/4 16:45
 */
@Configuration
@ComponentScan({"com.xugongzhang.autowire"})
public class MainConfigOfAutowired {
    
    @Primary
    @Bean
    public BookDao bookDao() {
        return new BookDao();
    }
    
    // 此时的参数car会从容器中获取，然后手动set进去
    @Conditional(BossCondition.class)
    @Bean
    public Boss boss(MyCar car) {
        Boss boss = new Boss();
        boss.setCar(car);
        return boss;
    }
}
